package o;

import android.content.res.ColorStateList;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.Matrix;
import android.graphics.Matrix.ScaleToFit;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Shader;
import android.graphics.Shader.TileMode;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.widget.ImageView.ScaleType;
import androidx.annotation.NonNull;
import java.util.HashSet;
import java.util.Set;

public class dkw extends Drawable {
    private final int ʻ;
    private float ʻॱ = 0.0f;
    private final int ʼ;
    private final Matrix ʽ = new Matrix();
    private final Bitmap ˊ;
    private boolean ˊॱ = true;
    private final Paint ˋ;
    private TileMode ˋॱ = TileMode.CLAMP;
    private final RectF ˎ = new RectF();
    private final RectF ˏ = new RectF();
    private final RectF ˏॱ = new RectF();
    private TileMode ͺ = TileMode.CLAMP;
    private final RectF ॱ = new RectF();
    private final boolean[] ॱˊ = new boolean[]{true, true, true, true};
    private ScaleType ॱˋ = ScaleType.FIT_CENTER;
    private float ॱˎ = 0.0f;
    private final Paint ॱॱ;
    private boolean ॱᐝ = false;
    private final RectF ᐝ = new RectF();
    private ColorStateList ᐝॱ = ColorStateList.valueOf(-16777216);

    static /* synthetic */ class AnonymousClass3 {
        static final /* synthetic */ int[] ˊ = new int[ScaleType.values().length];

        static {
            try {
                ˊ[ScaleType.CENTER.ordinal()] = 1;
            } catch (NoSuchFieldError e) {
            }
            try {
                ˊ[ScaleType.CENTER_CROP.ordinal()] = 2;
            } catch (NoSuchFieldError e2) {
            }
            try {
                ˊ[ScaleType.CENTER_INSIDE.ordinal()] = 3;
            } catch (NoSuchFieldError e3) {
            }
            try {
                ˊ[ScaleType.FIT_CENTER.ordinal()] = 4;
            } catch (NoSuchFieldError e4) {
            }
            try {
                ˊ[ScaleType.FIT_END.ordinal()] = 5;
            } catch (NoSuchFieldError e5) {
            }
            try {
                ˊ[ScaleType.FIT_START.ordinal()] = 6;
            } catch (NoSuchFieldError e6) {
            }
            try {
                ˊ[ScaleType.FIT_XY.ordinal()] = 7;
            } catch (NoSuchFieldError e7) {
            }
        }
    }

    public dkw(Bitmap bitmap) {
        this.ˊ = bitmap;
        this.ʼ = bitmap.getWidth();
        this.ʻ = bitmap.getHeight();
        this.ˏ.set(0.0f, 0.0f, (float) this.ʼ, (float) this.ʻ);
        this.ˋ = new Paint();
        this.ˋ.setStyle(Style.FILL);
        this.ˋ.setAntiAlias(true);
        this.ॱॱ = new Paint();
        this.ॱॱ.setStyle(Style.STROKE);
        this.ॱॱ.setAntiAlias(true);
        this.ॱॱ.setColor(this.ᐝॱ.getColorForState(getState(), -16777216));
        this.ॱॱ.setStrokeWidth(this.ॱˎ);
    }

    public static dkw ˎ(Bitmap bitmap) {
        if (bitmap != null) {
            return new dkw(bitmap);
        }
        return null;
    }

    public static Drawable ˎ(Drawable drawable) {
        if (drawable == null || (drawable instanceof dkw)) {
            return drawable;
        }
        if (drawable instanceof LayerDrawable) {
            LayerDrawable layerDrawable = (LayerDrawable) drawable;
            int numberOfLayers = layerDrawable.getNumberOfLayers();
            for (int i = 0; i < numberOfLayers; i++) {
                layerDrawable.setDrawableByLayerId(layerDrawable.getId(i), ˎ(layerDrawable.getDrawable(i)));
            }
            return layerDrawable;
        }
        Bitmap ˏ = ˏ(drawable);
        if (ˏ != null) {
            return new dkw(ˏ);
        }
        return drawable;
    }

    public static Bitmap ˏ(Drawable drawable) {
        if (drawable instanceof BitmapDrawable) {
            return ((BitmapDrawable) drawable).getBitmap();
        }
        try {
            Bitmap createBitmap = Bitmap.createBitmap(Math.max(drawable.getIntrinsicWidth(), 2), Math.max(drawable.getIntrinsicHeight(), 2), Config.ARGB_8888);
            Canvas canvas = new Canvas(createBitmap);
            drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
            drawable.draw(canvas);
            return createBitmap;
        } catch (Exception e) {
            Logger.ˋ("RoundedDrawable", "Failed to create bitmap from drawable!");
            return null;
        }
    }

    private static boolean ˋ(boolean[] zArr) {
        for (boolean z : zArr) {
            if (z) {
                return true;
            }
        }
        return false;
    }

    private static boolean ˏ(boolean[] zArr) {
        for (boolean z : zArr) {
            if (z) {
                return false;
            }
        }
        return true;
    }

    public boolean isStateful() {
        return this.ᐝॱ.isStateful();
    }

    protected boolean onStateChange(int[] iArr) {
        int colorForState = this.ᐝॱ.getColorForState(iArr, 0);
        if (this.ॱॱ.getColor() == colorForState) {
            return super.onStateChange(iArr);
        }
        this.ॱॱ.setColor(colorForState);
        return true;
    }

    private void ˋ() {
        float f = 0.0f;
        float height;
        float width;
        switch (AnonymousClass3.ˊ[this.ॱˋ.ordinal()]) {
            case 1:
                this.ᐝ.set(this.ˎ);
                this.ᐝ.inset(this.ॱˎ / 2.0f, this.ॱˎ / 2.0f);
                this.ʽ.reset();
                this.ʽ.setTranslate((float) ((int) (((this.ᐝ.width() - ((float) this.ʼ)) * 0.5f) + 0.5f)), (float) ((int) (((this.ᐝ.height() - ((float) this.ʻ)) * 0.5f) + 0.5f)));
                break;
            case 2:
                this.ᐝ.set(this.ˎ);
                this.ᐝ.inset(this.ॱˎ / 2.0f, this.ॱˎ / 2.0f);
                this.ʽ.reset();
                if (((float) this.ʼ) * this.ᐝ.height() > this.ᐝ.width() * ((float) this.ʻ)) {
                    height = this.ᐝ.height() / ((float) this.ʻ);
                    width = (this.ᐝ.width() - (((float) this.ʼ) * height)) * 0.5f;
                } else {
                    height = this.ᐝ.width() / ((float) this.ʼ);
                    width = 0.0f;
                    f = (this.ᐝ.height() - (((float) this.ʻ) * height)) * 0.5f;
                }
                this.ʽ.setScale(height, height);
                this.ʽ.postTranslate(((float) ((int) (width + 0.5f))) + (this.ॱˎ / 2.0f), ((float) ((int) (f + 0.5f))) + (this.ॱˎ / 2.0f));
                break;
            case 3:
                this.ʽ.reset();
                if (((float) this.ʼ) > this.ˎ.width() || ((float) this.ʻ) > this.ˎ.height()) {
                    f = Math.min(this.ˎ.width() / ((float) this.ʼ), this.ˎ.height() / ((float) this.ʻ));
                } else {
                    f = 1.0f;
                }
                width = (float) ((int) (((this.ˎ.width() - (((float) this.ʼ) * f)) * 0.5f) + 0.5f));
                height = (float) ((int) (((this.ˎ.height() - (((float) this.ʻ) * f)) * 0.5f) + 0.5f));
                this.ʽ.setScale(f, f);
                this.ʽ.postTranslate(width, height);
                this.ᐝ.set(this.ˏ);
                this.ʽ.mapRect(this.ᐝ);
                this.ᐝ.inset(this.ॱˎ / 2.0f, this.ॱˎ / 2.0f);
                this.ʽ.setRectToRect(this.ˏ, this.ᐝ, ScaleToFit.FILL);
                break;
            case 5:
                this.ᐝ.set(this.ˏ);
                this.ʽ.setRectToRect(this.ˏ, this.ˎ, ScaleToFit.END);
                this.ʽ.mapRect(this.ᐝ);
                this.ᐝ.inset(this.ॱˎ / 2.0f, this.ॱˎ / 2.0f);
                this.ʽ.setRectToRect(this.ˏ, this.ᐝ, ScaleToFit.FILL);
                break;
            case 6:
                this.ᐝ.set(this.ˏ);
                this.ʽ.setRectToRect(this.ˏ, this.ˎ, ScaleToFit.START);
                this.ʽ.mapRect(this.ᐝ);
                this.ᐝ.inset(this.ॱˎ / 2.0f, this.ॱˎ / 2.0f);
                this.ʽ.setRectToRect(this.ˏ, this.ᐝ, ScaleToFit.FILL);
                break;
            case 7:
                this.ᐝ.set(this.ˎ);
                this.ᐝ.inset(this.ॱˎ / 2.0f, this.ॱˎ / 2.0f);
                this.ʽ.reset();
                this.ʽ.setRectToRect(this.ˏ, this.ᐝ, ScaleToFit.FILL);
                break;
            default:
                this.ᐝ.set(this.ˏ);
                this.ʽ.setRectToRect(this.ˏ, this.ˎ, ScaleToFit.CENTER);
                this.ʽ.mapRect(this.ᐝ);
                this.ᐝ.inset(this.ॱˎ / 2.0f, this.ॱˎ / 2.0f);
                this.ʽ.setRectToRect(this.ˏ, this.ᐝ, ScaleToFit.FILL);
                break;
        }
        this.ॱ.set(this.ᐝ);
    }

    protected void onBoundsChange(@NonNull Rect rect) {
        super.onBoundsChange(rect);
        this.ˎ.set(rect);
        ˋ();
    }

    public void draw(@NonNull Canvas canvas) {
        if (this.ˊॱ) {
            Shader bitmapShader = new BitmapShader(this.ˊ, this.ˋॱ, this.ͺ);
            if (this.ˋॱ == TileMode.CLAMP && this.ͺ == TileMode.CLAMP) {
                bitmapShader.setLocalMatrix(this.ʽ);
            }
            this.ˋ.setShader(bitmapShader);
            this.ˊॱ = false;
        }
        if (this.ॱᐝ) {
            if (this.ॱˎ > 0.0f) {
                canvas.drawOval(this.ॱ, this.ˋ);
                canvas.drawOval(this.ᐝ, this.ॱॱ);
                return;
            }
            canvas.drawOval(this.ॱ, this.ˋ);
        } else if (ˋ(this.ॱˊ)) {
            float f = this.ʻॱ;
            if (this.ॱˎ > 0.0f) {
                canvas.drawRoundRect(this.ॱ, f, f, this.ˋ);
                canvas.drawRoundRect(this.ᐝ, f, f, this.ॱॱ);
                ˎ(canvas);
                ॱ(canvas);
                return;
            }
            canvas.drawRoundRect(this.ॱ, f, f, this.ˋ);
            ˎ(canvas);
        } else {
            canvas.drawRect(this.ॱ, this.ˋ);
            if (this.ॱˎ > 0.0f) {
                canvas.drawRect(this.ᐝ, this.ॱॱ);
            }
        }
    }

    private void ˎ(Canvas canvas) {
        if (!ˏ(this.ॱˊ) && this.ʻॱ != 0.0f) {
            float f = this.ॱ.left;
            float f2 = this.ॱ.top;
            float width = this.ॱ.width() + f;
            float height = this.ॱ.height() + f2;
            float f3 = this.ʻॱ;
            if (!this.ॱˊ[0]) {
                this.ˏॱ.set(f, f2, f + f3, f2 + f3);
                canvas.drawRect(this.ˏॱ, this.ˋ);
            }
            if (!this.ॱˊ[1]) {
                this.ˏॱ.set(width - f3, f2, width, f3);
                canvas.drawRect(this.ˏॱ, this.ˋ);
            }
            if (!this.ॱˊ[2]) {
                this.ˏॱ.set(width - f3, height - f3, width, height);
                canvas.drawRect(this.ˏॱ, this.ˋ);
            }
            if (!this.ॱˊ[3]) {
                this.ˏॱ.set(f, height - f3, f3 + f, height);
                canvas.drawRect(this.ˏॱ, this.ˋ);
            }
        }
    }

    private void ॱ(Canvas canvas) {
        if (!ˏ(this.ॱˊ) && this.ʻॱ != 0.0f) {
            float f = this.ॱ.left;
            float f2 = this.ॱ.top;
            float width = f + this.ॱ.width();
            float height = f2 + this.ॱ.height();
            float f3 = this.ʻॱ;
            float f4 = this.ॱˎ / 2.0f;
            if (!this.ॱˊ[0]) {
                canvas.drawLine(f - f4, f2, f + f3, f2, this.ॱॱ);
                canvas.drawLine(f, f2 - f4, f, f2 + f3, this.ॱॱ);
            }
            if (!this.ॱˊ[1]) {
                canvas.drawLine((width - f3) - f4, f2, width, f2, this.ॱॱ);
                canvas.drawLine(width, f2 - f4, width, f2 + f3, this.ॱॱ);
            }
            if (!this.ॱˊ[2]) {
                canvas.drawLine((width - f3) - f4, height, width + f4, height, this.ॱॱ);
                canvas.drawLine(width, height - f3, width, height, this.ॱॱ);
            }
            if (!this.ॱˊ[3]) {
                canvas.drawLine(f - f4, height, f + f3, height, this.ॱॱ);
                canvas.drawLine(f, height - f3, f, height, this.ॱॱ);
            }
        }
    }

    public int getOpacity() {
        return -3;
    }

    public int getAlpha() {
        return this.ˋ.getAlpha();
    }

    public void setAlpha(int i) {
        this.ˋ.setAlpha(i);
        invalidateSelf();
    }

    public ColorFilter getColorFilter() {
        return this.ˋ.getColorFilter();
    }

    public void setColorFilter(ColorFilter colorFilter) {
        this.ˋ.setColorFilter(colorFilter);
        invalidateSelf();
    }

    public void setDither(boolean z) {
        this.ˋ.setDither(z);
        invalidateSelf();
    }

    public void setFilterBitmap(boolean z) {
        this.ˋ.setFilterBitmap(z);
        invalidateSelf();
    }

    public int getIntrinsicWidth() {
        return this.ʼ;
    }

    public int getIntrinsicHeight() {
        return this.ʻ;
    }

    public dkw ˏ(float f, float f2, float f3, float f4) {
        boolean z = true;
        Set hashSet = new HashSet(4);
        hashSet.add(Float.valueOf(f));
        hashSet.add(Float.valueOf(f2));
        hashSet.add(Float.valueOf(f3));
        hashSet.add(Float.valueOf(f4));
        hashSet.remove(Float.valueOf(0.0f));
        if (hashSet.size() > 1) {
            throw new IllegalArgumentException("Multiple nonzero corner radii not yet supported.");
        }
        boolean z2;
        if (hashSet.isEmpty()) {
            this.ʻॱ = 0.0f;
        } else {
            float floatValue = ((Float) hashSet.iterator().next()).floatValue();
            if (Float.isInfinite(floatValue) || Float.isNaN(floatValue) || floatValue < 0.0f) {
                throw new IllegalArgumentException("Invalid radius value: " + floatValue);
            }
            this.ʻॱ = floatValue;
        }
        boolean[] zArr = this.ॱˊ;
        if (f > 0.0f) {
            z2 = true;
        } else {
            z2 = false;
        }
        zArr[0] = z2;
        zArr = this.ॱˊ;
        if (f2 > 0.0f) {
            z2 = true;
        } else {
            z2 = false;
        }
        zArr[1] = z2;
        zArr = this.ॱˊ;
        if (f3 > 0.0f) {
            z2 = true;
        } else {
            z2 = false;
        }
        zArr[2] = z2;
        boolean[] zArr2 = this.ॱˊ;
        if (f4 <= 0.0f) {
            z = false;
        }
        zArr2[3] = z;
        return this;
    }

    public dkw ˋ(float f) {
        this.ॱˎ = f;
        this.ॱॱ.setStrokeWidth(this.ॱˎ);
        return this;
    }

    public dkw ˊ(ColorStateList colorStateList) {
        if (colorStateList == null) {
            colorStateList = ColorStateList.valueOf(0);
        }
        this.ᐝॱ = colorStateList;
        this.ॱॱ.setColor(this.ᐝॱ.getColorForState(getState(), -16777216));
        return this;
    }

    public dkw ˏ(boolean z) {
        this.ॱᐝ = z;
        return this;
    }

    public dkw ˏ(ScaleType scaleType) {
        if (scaleType == null) {
            scaleType = ScaleType.FIT_CENTER;
        }
        if (this.ॱˋ != scaleType) {
            this.ॱˋ = scaleType;
            ˋ();
        }
        return this;
    }

    public dkw ˋ(TileMode tileMode) {
        if (this.ˋॱ != tileMode) {
            this.ˋॱ = tileMode;
            this.ˊॱ = true;
            invalidateSelf();
        }
        return this;
    }

    public dkw ˏ(TileMode tileMode) {
        if (this.ͺ != tileMode) {
            this.ͺ = tileMode;
            this.ˊॱ = true;
            invalidateSelf();
        }
        return this;
    }
}
